package com.miyu.writenum;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SelectActivity extends Activity {

    MediaPlayer mediaPlayer;
    @BindView(R.id.num1)
    ImageView num1;
    @BindView(R.id.num2)
    ImageView num2;
    @BindView(R.id.num3)
    ImageView num3;
    @BindView(R.id.num4)
    ImageView num4;
    @BindView(R.id.num5)
    ImageView num5;
    @BindView(R.id.num6)
    ImageView num6;
    @BindView(R.id.num7)
    ImageView num7;
    @BindView(R.id.num8)
    ImageView num8;
    @BindView(R.id.num9)
    ImageView num9;
    @BindView(R.id.num0)
    ImageView num0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select);
        ButterKnife.bind(this);
        if (MainActivity.isPlay) {
            PlayMusic();

        }
    }

    /**
     * 数字界面音乐播放
     */
    private void PlayMusic() {
        mediaPlayer = MediaPlayer.create(this, R.raw.number_music);
        mediaPlayer.setLooping(true);
        mediaPlayer.start();
    }

    /**
     * 数字界面音乐停止
     */
    @Override
    protected void onStop() {
        super.onStop();
        if (mediaPlayer != null) {
            mediaPlayer.stop();
            mediaPlayer.release();
            mediaPlayer = null;

        }
    }

    /**
     * 从另外界面进入数字界面判断是否停止音乐
     */
    @Override
    protected void onRestart() {
        super.onRestart();
        if (MainActivity.isPlay) {
            PlayMusic();
        }
    }

    @OnClick({R.id.num1, R.id.num2, R.id.num3, R.id.num4, R.id.num5, R.id.num6, R.id.num7, R.id.num8, R.id.num9, R.id.num0})
    public void onViewClicked(View view) {
        Intent intent = new Intent(SelectActivity.this,NumberActivity.class);
        switch (view.getId()) {
            case R.id.num1:

                intent.putExtra("number","1");
                startActivity(intent);

                break;
            case R.id.num2:
                intent.putExtra("number","2");
                startActivity(intent);
                break;
            case R.id.num3:
                intent.putExtra("number","3");
                startActivity(intent);
                break;
            case R.id.num4:
                intent.putExtra("number","4");
                startActivity(intent);
                break;
            case R.id.num5:
                intent.putExtra("number","5");
                startActivity(intent);
                break;
            case R.id.num6:
                intent.putExtra("number","6");
                startActivity(intent);
                break;
            case R.id.num7:
                intent.putExtra("number","7");
                startActivity(intent);
                break;
            case R.id.num8:
                intent.putExtra("number","8");
                startActivity(intent);
                break;
            case R.id.num9:
                intent.putExtra("number","9");
                startActivity(intent);
                break;
            case R.id.num0:
                intent.putExtra("number","0");
                startActivity(intent);
                break;
        }
    }
}
